class_name UITitle
extends Control

@onready var title: Label = $Title/Title
@onready var push_key_continue: Label = $Title/PushKeyContinue
@onready var animation_player: AnimationPlayer = $AnimationPlayer

@onready var start_new_game_button: UISimpleButton = $Options/StartNewGame
@onready var continue_game_button: UISimpleButton = $Options/ContinueGame
@onready var window_mode_setting: UISimpleButton = $Options/WindowModeSetting
@onready var about_button: UISimpleButton = $Options/About
@onready var exit_button: UISimpleButton = $Options/Exit

var level: TitleLevel = null

# window option button
@onready var borderless_full_screen_button: UISimpleButton = $WindowModeOptions/BorderlessFullScreen
@onready var full_screen_button: UISimpleButton = $WindowModeOptions/FullScreen
@onready var windowed_button: UISimpleButton = $WindowModeOptions/Windowed


func _ready() -> void:
	start_new_game_button.signal_on_click.connect(on_start_new_game)
	continue_game_button.signal_on_click.connect(on_continue_game)
	window_mode_setting.signal_on_click.connect(on_window_mode_setting)
	about_button.signal_on_click.connect(on_about_button_click)
	exit_button.signal_on_click.connect(on_exit_game)
	borderless_full_screen_button.signal_on_click.connect(on_borderless_full_screen_button_click)
	full_screen_button.signal_on_click.connect(on_full_screen_button_click)
	windowed_button.signal_on_click.connect(on_windowed_button_click)
	
	if not GameManager.has_save_file():
		continue_game_button.visible = false
		continue_game_button.is_enable = false
		about_button.position.y -= 10
		window_mode_setting.position.y -= 10
		exit_button.position.y -= 10
		

func on_about_button_click():
	level.on_about_click()
		

func on_borderless_full_screen_button_click():
	level.on_borderless_full_screen_button_click()


func on_full_screen_button_click():
	level.on_full_screen_button_click()
	

func on_windowed_button_click():
	level.on_windowed_button_click()


func on_window_mode_setting():
	level.on_window_mode_setting()


func on_start_new_game():
	level.on_start_new_game()
	

func on_continue_game():
	level.on_continue_game()


func on_exit_game():
	get_tree().quit()


func show_title() -> AnimationPlayer:
	animation_player.play("show_title")
	return animation_player
	
	
func hide_title() -> AnimationPlayer:
	animation_player.play("hide_title")
	return animation_player
	
	
func show_options():
	animation_player.play("show_options")
	return animation_player
	
	
func hide_options() -> AnimationPlayer:
	animation_player.play("hide_options")
	return animation_player
	

func show_window_options() -> AnimationPlayer:
	animation_player.play("show_window_options")
	return animation_player
	

func hide_window_options() -> AnimationPlayer:
	animation_player.play("hide_window_options")
	return animation_player
	

func flicker_continue() -> AnimationPlayer:
	animation_player.play("flicker_continue")
	return animation_player
	

func enable_all_option():
	about_button.is_enable = true
	start_new_game_button.is_enable = true
	if continue_game_button.visible:
		continue_game_button.is_enable = true
	window_mode_setting.is_enable = true
	exit_button.is_enable = true


func disable_all_option():
	about_button.is_enable = false
	start_new_game_button.is_enable = false
	continue_game_button.is_enable = false
	window_mode_setting.is_enable = false
	exit_button.is_enable = false
